package com.geekaca.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = {"/hello","/demo1"}, loadOnStartup = 1)
public class HelloServlet extends HttpServlet {
    //    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        // 接收get请求
//        doPost(req, resp);
//    }
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        // 接收post请求
//        String uname = req.getParameter("uname");
//        System.out.println("username: " + uname);
//    }
    public HelloServlet() {
        System.out.println("构造器================");

    }


    @Override
    public void destroy() {
        System.out.println("destory 被调用");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("init 被调用");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 即可接收GET,又可以接收POST
        System.out.println("service .................");
        System.out.println(req.getParameter("s"));
    }

}
